package com.daffodil.workable.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.daffodil.core.annotation.AuthPermission;
import com.daffodil.core.annotation.Log;
import com.daffodil.core.annotation.Log.BusinessType;
import com.daffodil.core.controller.ReactiveBaseController;
import com.daffodil.core.entity.JsonResult;
import com.daffodil.workable.constant.WorkableConstant;
import com.daffodil.workable.controller.model.WorkableJsPlumbData;
import com.daffodil.workable.service.IWorkableJsPlumbDataService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import reactor.core.publisher.Mono;
import springfox.documentation.annotations.ApiIgnore;

/**
 * -任务工作流数据管理
 * @author yweijian
 * @date 2022年4月7日
 * @version 1.0
 * @description
 */
@Api(value = "任务工作流数据管理", tags = "任务工作流数据管理")
@RestController
@RequestMapping(WorkableConstant.API_CONTENT_PATH + "/jsplumbdata")
public class WorkableJsPlumbDataController extends ReactiveBaseController{

    @Autowired
    private IWorkableJsPlumbDataService workableJsPlumbDataService;
    
    @ApiOperation("获取工作流数据")
    @ApiImplicitParam(name = HttpHeaders.AUTHORIZATION, value = "登录授权令牌 Bearer token", paramType = "header", required = true)
    @AuthPermission("workable:jsplumbdata:info")
    @GetMapping("/info")
    public Mono<JsonResult> info(@ApiParam(value = "计划任务ID") String taskId, @ApiIgnore ServerHttpRequest request) {
        WorkableJsPlumbData jsPlumbData = workableJsPlumbDataService.selectWorkableJsPlumbDataByTaskId(taskId);
        return JsonResult.success(jsPlumbData).getMono();
    }
    
    @ApiOperation("保存工作流数据")
    @ApiImplicitParam(name = HttpHeaders.AUTHORIZATION, value = "登录授权令牌 Bearer token", paramType = "header", required = true)
    @AuthPermission("workable:jsplumbdata:save")
    @Log(title = "任务工作流数据管理", businessType = BusinessType.INSERT)
    @PostMapping("/save")
    public Mono<JsonResult> save(@Validated @RequestBody WorkableJsPlumbData jsPlumbData, @ApiIgnore ServerHttpRequest request) {
        workableJsPlumbDataService.saveWorkableJsPlumbData(jsPlumbData);
        return JsonResult.success(jsPlumbData).getMono();
    }
}
